package com.coursehub.shared.transaction;

/**
 * 分布式事务状态枚举
 */
public enum TransactionStatus {
    
    /**
     * 事务已创建
     */
    CREATED("已创建"),
    
    /**
     * 事务执行中
     */
    EXECUTING("执行中"),
    
    /**
     * 事务执行成功
     */
    SUCCESS("执行成功"),
    
    /**
     * 事务执行失败
     */
    FAILED("执行失败"),
    
    /**
     * 事务补偿中
     */
    COMPENSATING("补偿中"),
    
    /**
     * 事务补偿成功
     */
    COMPENSATED("补偿成功"),
    
    /**
     * 事务补偿失败
     */
    COMPENSATION_FAILED("补偿失败"),
    
    /**
     * 事务已取消
     */
    CANCELLED("已取消"),
    
    /**
     * 事务不存在
     */
    NOT_FOUND("不存在");
    
    private final String description;
    
    TransactionStatus(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 检查是否为终态
     */
    public boolean isTerminal() {
        return this == SUCCESS || 
               this == FAILED || 
               this == COMPENSATED || 
               this == COMPENSATION_FAILED || 
               this == CANCELLED || 
               this == NOT_FOUND;
    }
    
    /**
     * 检查是否为成功状态
     */
    public boolean isSuccess() {
        return this == SUCCESS;
    }
    
    /**
     * 检查是否为失败状态
     */
    public boolean isFailure() {
        return this == FAILED || this == COMPENSATION_FAILED;
    }
}